#include "status_notify.h"

Status_Notify::Status_Notify(Http_Post *parent) :
    Http_Post(parent)
{

}

Status_Notify::~Status_Notify()
{

}

void Status_Notify::m_post(QString host,
                          QString uin,
                          QString sid,
                          QString skey,
                          QString deviceId,
                          QString userName)
{
    QString ts = QString::number(time(NULL));
    QString url = host + WX_CGI_PATH + "webwxstatusnotify?skey=" + skey + "&r=" + ts;
#if QWX_DEBUG
    qDebug() << "DEBUG:" << __PRETTY_FUNCTION__ << url;
#endif
    QString json = "{\"BaseRequest\":{\"Uin\":" + uin + ",\"Sid\":\"" + sid
        + "\",\"Skey\":\"\",\"DeviceID\":\"" + deviceId + "\"},\"Code\":3,"
        "\"FromUserName\":\"" + userName + "\",\"ToUserName\":\"" + userName
        + "\",\"ClientMsgId\":\"" + ts + "\"}";
#if QWX_DEBUG
    qDebug() << "DEBUG:" << __PRETTY_FUNCTION__ << json;
#endif
    Http_Post::post(url, json, true);
}

void Status_Notify::postV2(QString uin, QString sid,
                          QString skey, QString deviceId, QString userName)
{
    m_post(WX_V2_SERVER_HOST, uin, sid, skey, deviceId, userName);
}

void Status_Notify::finished(QNetworkReply* reply)
{
    QString replyStr = QString(reply->readAll());
#if QWX_DEBUG
    qDebug() << "DEBUG:" << __PRETTY_FUNCTION__;
    qDebug() << "DEBUG:" << replyStr;
#endif
}
